package org.ainlolcat.ainscience2.model.impl;

import org.ainlolcat.ainscience2.model.Entity;
import org.ainlolcat.ainscience2.model.data.Column;
import org.ainlolcat.ainscience2.model.filter.Filter;
import org.ainlolcat.ainscience2.model.filter.FilterApplier;
import org.ainlolcat.ainscience2.model.filter.impl.ColumnNameFilter;

import java.util.Collection;
import java.util.List;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: ain
 * Date: 17.06.12
 * Time: 1:10
 * To change this template use File | Settings | File Templates.
 */
public class EntityImpl implements Entity {
    List<Column> columns = new Vector<Column>();
    String name;
    String namespace;

    public String getName() {
        return name;
    }

    public String getNamespace() {
        return namespace;
    }

    public int size() {
        return columns.size();
    }

    public Column getColumn(int index) {
        return columns.get(index);
    }

    public Column getColumn(String name) {
        Collection<Column> subres = getColumns(new ColumnNameFilter(name));
        if (subres == null || subres.size()==0){
            return null;
        }
        return getColumns(new ColumnNameFilter(name)).iterator().next();
    }

    public Collection<Column> getColumns(Filter... filters) {
        return new FilterApplier().apply(columns, filters);
    }
}
